﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MediaImporter.Controls
{
    public partial class ProgressControl : UserControl
    {
        public event EventHandler AbortPressed;

        public ProgressControl()
        {
            InitializeComponent();
        }

        public void SetProgress(int progress)
        {
            labelProgress.Text = string.Format("{0} of {1} done.", progress, total);
            progressBar1.Value = progress;
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.Visible = false;
        }

        private void buttonStop_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure to abort?","Copying files",MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                this.Enabled = false;
                if (AbortPressed != null)
                    AbortPressed(this, EventArgs.Empty);
            }
        }
        private int total;
        public void Show(int total, string description)
        {
            this.Visible = true;
            this.Enabled = true;
            progressBar1.Maximum = total;
            this.total = total;
            progressBar1.Step = total / 100;
            if (progressBar1.Step == 0 && total!=0)
                progressBar1.Step = 100 / total;
            SetProgress(0);
            labelOperation.Text = description;
        }
    }
}
